//
//  RKTabBarCtrl.swift
//  RKTemplate
//
//  Created by zhaoke on 2023/7/23.
//

import Foundation
import UIKit
import ESTabBarController_swift

class RKTabBarCtrl: ESTabBarController {
    override func viewDidLoad() {
        super.viewDidLoad()
        setUpChildrenVCs()
        self.setTabbar()
    }
    func setUpChildrenVCs () {
        //
        let vc1 = RKNavigationCtrl(rootViewController: HomeCtrl())
        let vc2 = RKNavigationCtrl(rootViewController: ClassifyCtrl())
        let vc3 = RKNavigationCtrl(rootViewController: MessageCtrl())
        let vc4 = RKNavigationCtrl(rootViewController: MineCtrl())
        let vcs = [vc1, vc2, vc3, vc4]
        let titles = ["首页", "分类", "消息", "我的"]
        let normalImages = ["icon1_tabbar_normal", "icon2_tabbar_normal", "icon3_tabbar_normal", "icon4_tabbar_normal"]
        let selectImages = ["icon1_tabbar_sel", "icon2_tabbar_sel", "icon3_tabbar_sel", "icon4_tabbar_sel"]
        for index in 0...3 {
            let contentView = RKBouncesContentView()
            contentView.renderingMode = .alwaysOriginal
            let tabBarItem = ESTabBarItem(contentView, title: titles[index], image: UIImage(named: normalImages[index]), selectedImage: UIImage(named: selectImages[index]), tag: index)
            vcs[index].tabBarItem = tabBarItem
        }
        viewControllers = vcs
    }
}
extension UITabBarController {
    func setTabbar() {
        view.backgroundColor = .white
        UITabBar.appearance().backgroundColor = .white
        UITabBar.appearance().isTranslucent = false
        let appearance = tabBar.standardAppearance
        appearance.backgroundImage = UIImage(rk_color: .white)
        appearance.shadowImage = UIImage()
        tabBar.standardAppearance = appearance
        if #available(iOS 15.0, *) {
            tabBar.scrollEdgeAppearance = appearance
        }
    }
}
